package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.shop.dao.SetMealDAO;
import com.junzhiit.nengji.shop.model.SetMeal;

@Repository
public class SetMealDAOImpl extends AbstractBaseDAO<SetMeal> implements SetMealDAO {

	@Override
	public List<SetMeal> findAll(SetMeal setMeal,int pageNumber, int maxPageRow) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from set_meal");
		sql.append(" where is_delete =?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(StringUtils.isNoneBlank(setMeal.getName())){
			sql.append(" and name like ?");
			params.setString("%"+setMeal.getName()+"%");
		}
		return super.queryForPagingList(sql.toString(), SetMeal.class, params, pageNumber,maxPageRow);
	}

	@Override
	public Integer getTotalCount(SetMeal setMeal) {
		StringBuffer sql = new StringBuffer();
		sql.append("select count(id) from set_meal");
		sql.append(" where is_delete =?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		return super.queryForInt(sql.toString(),params);
	}

	@Override
	public SetMeal getSetMealById(String id) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from set_meal");
		sql.append(" where is_delete =?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(StringUtils.isNoneBlank(id)){
			sql.append(" and id =?");
			params.setString(id);
		}
		return super.query(sql.toString(),SetMeal.class,params);
	}

	@Override
	public List<SetMeal> getSetMealList(SetMeal setMeal) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from set_meal");
		sql.append(" where is_delete =?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(setMeal.getType()!=null){
			sql.append(" and type= ? ");
			params.setInt(setMeal.getType());
		}
		if(setMeal.getIsOpenFree()!=null){
			sql.append(" and is_open_free= ? ");
			params.setInt(setMeal.getIsOpenFree());
		}
		
		sql.append(" order by money desc");
		return super.queryForList(sql.toString(), SetMeal.class, params);
	}

	@Override
	public List<SetMeal> findConciseAll(SetMeal setMeal) {
		StringBuffer sql = new StringBuffer();
		sql.append("select id,name from set_meal");
		sql.append(" where is_delete =?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(StringUtils.isNoneBlank(setMeal.getName())){
			sql.append(" and name like ?");
			params.setString("%"+setMeal.getName()+"%");
		}
		return super.queryForList(sql.toString(), SetMeal.class, params);
	}

	
}
